package com.ruoyi.project.inspection.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.inspection.domain.ViOperLog;
import com.ruoyi.project.inspection.service.IViOperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车辆年检操作记录Controller
 *
 * @author ruoyi
 * @date 2020-07-17
 */
@RestController
@RequestMapping("/inspection/vilog")
public class ViOperLogController extends BaseController {
    @Autowired
    private IViOperLogService viOperLogService;

    /**
     * 查询车辆年检操作记录列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:vilog:list')")
    @GetMapping("/list")
    public TableDataInfo list(ViOperLog viOperLog) {
        startPage();
        List<ViOperLog> list = viOperLogService.selectViOperLogList(viOperLog);
        return getDataTable(list);
    }

    /**
     * 导出车辆年检操作记录列表
     */
    @PreAuthorize("@ss.hasPermi('inspection:vilog:export')")
    @Log(title = "车辆年检操作记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ViOperLog viOperLog) {
        List<ViOperLog> list = viOperLogService.selectViOperLogList(viOperLog);
        ExcelUtil<ViOperLog> util = new ExcelUtil<ViOperLog>(ViOperLog.class);
        return util.exportExcel(list, "vilog");
    }

    /**
     * 获取车辆年检操作记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('inspection:vilog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(viOperLogService.selectViOperLogById(id));
    }

    /**
     * 新增车辆年检操作记录
     */
    @PreAuthorize("@ss.hasPermi('inspection:vilog:add')")
    @Log(title = "车辆年检操作记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ViOperLog viOperLog) {
        return toAjax(viOperLogService.insertViOperLog(viOperLog));
    }

    /**
     * 修改车辆年检操作记录
     */
    @PreAuthorize("@ss.hasPermi('inspection:vilog:edit')")
    @Log(title = "车辆年检操作记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ViOperLog viOperLog) {
        return toAjax(viOperLogService.updateViOperLog(viOperLog));
    }

    /**
     * 删除车辆年检操作记录
     */
    @PreAuthorize("@ss.hasPermi('inspection:vilog:remove')")
    @Log(title = "车辆年检操作记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(viOperLogService.deleteViOperLogByIds(ids));
    }
}
